<?php
include_once('config/db_conn.php');
session_start();
require 'facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => APPID,
  'secret' => SECRET,
  'cookie' => true,
));

$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}
if ($me) {
unset($_SESSION['username']);
unset($_SESSION['user_id']);
unset($_SESSION['username_email']);
unset($_SESSION['user_name']);

$logoutUrl = $facebook->getLogoutUrl();
header("Location: $logoutUrl");
exit;
}



include_once('config/db_conn.php');
if(isset($_SESSION['username_email'])|| isset($_SESSION['user_id']) )
{
unset($_SESSION['username']);
unset($_SESSION['user_id']);
unset($_SESSION['username_email']);
unset($_SESSION['user_name']);

if(isSet($_COOKIE[$cookie_name]))
{
// remove 'site_auth' cookie
setcookie ($cookie_name, '', time() - $cookie_time);
}

//Now remove facebook

reDirect('index.php');

}

reDirect('index.php');
?>